package net.cyndeline

class MinMaxCounter extends Counter {
  private var current = 0
  private var minimum = 0
  private var maximum = 0
  
  override def min = minimum
  
  override def min_=(newMin: Int) {
    minimum = newMin
    
    if (maximum < minimum) maximum = minimum
    if (value < minimum) current = minimum
  }
  
  override def max = maximum
  
  override def max_=(newMax: Int) {
    maximum = newMax
    
    if (minimum > maximum) minimum = maximum
    if (value > maximum) current = maximum
  }
  
  override def value = current
  
  override def set(newValue: Int) {
    var setVal = newValue
    if (setVal < minimum) setVal = minimum
    if (setVal > maximum) setVal = maximum
    current = setVal
  } 
}